﻿
Shader "WSS/Standard/XRay"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
        _XRayColor("XRay Color", Color) = (1,1,1,1)
        _RimRatio("Rim Ratio", Range(0,1)) = 0
    }
    
    SubShader
    {
        Tags{ "Queue" = "Geometry+100" "RenderType" = "Opaque" }
        // Tags { "RenderType"="Opaque" }
        LOD 200
        
        //渲染X光效果的Pass
        Pass
        {
            Blend SrcAlpha One
            ZWrite Off
            ZTest Greater
            
            CGPROGRAM
            #include "Lighting.cginc"
            fixed4 _XRayColor;
            float _RimRatio;
            struct v2f
            {
                float4 pos : SV_POSITION;
                float3 normal : normal;
                float3 viewDir : TEXCOORD0;
            };
            
            v2f vert (appdata_base v)
            {
                v2f o;
                o.pos = UnityObjectToClipPos(v.vertex);
                o.viewDir = ObjSpaceViewDir(v.vertex);
                o.normal = v.normal;
                return o;
            }
            
            fixed4 frag(v2f i) : SV_Target
            {
                float3 normal = normalize(i.normal);
                float3 viewDir = normalize(i.viewDir);
                float rim = 1 - dot(normal, viewDir);
                return lerp(_XRayColor,_XRayColor * rim,1-_RimRatio);
            }
            #pragma vertex vert
            #pragma fragment frag
            ENDCG
        }
        
        //正常渲染的Pass
        
        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;
        
        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
        
        // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) ;
            
            o.Albedo = c.rgba * _Color;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    
    FallBack "Diffuse"
}